namespace DotNetNuke.UI.UserControls
{
    using DotNetNuke.Common;
    using DotNetNuke.Common.Utilities;
    using DotNetNuke.Entities.Modules;
    using DotNetNuke.Services.Exceptions;
    using DotNetNuke.Services.Localization;
    using Microsoft.VisualBasic.CompilerServices;
    using System;
    using System.Collections.Generic;
    using System.Diagnostics;
    using System.IO;
    using System.Runtime.CompilerServices;
    using System.Web.UI.WebControls;

    public class Help : PortalModuleBase
    {
        private static List<WeakReference> __ENCList = new List<WeakReference>();
        //("cmdCancel")]
        private LinkButton _cmdCancel;
        private string _key;
        protected HyperLink cmdHelp;
        protected Label lblHelp;

       
        public Help()
        {
            base.Load += new EventHandler(this.Page_Load);
            base.Init += new EventHandler(this.Page_Init);
            List<WeakReference> list = __ENCList;
            lock (list)
            {
                __ENCList.Add(new WeakReference(this));
            }
        }

        /// -----------------------------------------------------------------------------
        /// <summary>
        /// cmdCancel_Click runs when the cancel Button is clicked
        /// </summary>
        /// <remarks>
        /// </remarks>
        /// <history>
        /// </history>
        /// -----------------------------------------------------------------------------
        private void cmdCancel_Click(object sender, EventArgs e)
        {
            try
            {
                this.Response.Redirect(Convert.ToString(RuntimeHelpers.GetObjectValue(this.ViewState["UrlReferrer"])), true);
            }
            catch (Exception exception1)
            {
                
                Exception exc = exception1;
                DotNetNuke.Services.Exceptions.Exceptions.ProcessModuleLoadException((PortalModuleBase) this, exc);
                
            }
        }

        [DebuggerStepThrough]
        private void InitializeComponent()
        {
            this.ID = "Help";
        }

        private void Page_Init(object sender, EventArgs e)
        {
            this.InitializeComponent();
        }

        /// -----------------------------------------------------------------------------
        /// <summary>
        /// Page_Load runs when the control is loaded.
        /// </summary>
        /// <remarks>
        /// </remarks>
        /// <history>
        /// </history>
        /// -----------------------------------------------------------------------------
        private void Page_Load(object sender, EventArgs e)
        {
            string FriendlyName = "";
            DotNetNuke.Entities.Modules.ModuleInfo objModule = new ModuleController().GetModule(this.ModuleId, this.TabId);
            if (objModule != null)
            {
                FriendlyName = objModule.FriendlyName;
            }
            int ModuleControlId = Null.NullInteger;
            if (this.Request.QueryString["ctlid"] != null)
            {
                ModuleControlId = int.Parse(this.Request.QueryString["ctlid"]);
            }
            ModuleControlInfo objModuleControl = new ModuleControlController().GetModuleControl(ModuleControlId);
            if (objModuleControl != null)
            {
                string FileName = Path.GetFileName(objModuleControl.ControlSrc);
                string LocalResourceFile = objModuleControl.ControlSrc.Replace(FileName, "App_LocalResources/" + FileName);
                if (DotNetNuke.Services.Localization.Localization.GetString("ModuleHelp.Text", LocalResourceFile) != "")
                {
                    this.lblHelp.Text = DotNetNuke.Services.Localization.Localization.GetString("ModuleHelp.Text", LocalResourceFile);
                }
                this._key = objModuleControl.ControlKey;
                string helpUrl = Globals.GetOnLineHelp(objModuleControl.HelpURL, this.ModuleConfiguration);
                if (!Null.IsNull(helpUrl))
                {
                    this.cmdHelp.NavigateUrl = Globals.FormatHelpUrl(helpUrl, this.PortalSettings, FriendlyName);
                    this.cmdHelp.Visible = true;
                }
                else
                {
                    this.cmdHelp.Visible = false;
                }
            }
            if (!this.Page.IsPostBack)
            {
                if (this.Request.UrlReferrer != null)
                {
                    this.ViewState["UrlReferrer"] = Convert.ToString(this.Request.UrlReferrer);
                }
                else
                {
                    this.ViewState["UrlReferrer"] = "";
                }
            }
        }

        protected virtual LinkButton cmdCancel
        {
           
            get
            {
                return this._cmdCancel;
            }
            
            set
            {
                EventHandler handler = new EventHandler(this.cmdCancel_Click);
                if (this._cmdCancel != null)
                {
                    this._cmdCancel.Click -= handler;
                }
                this._cmdCancel = value;
                if (this._cmdCancel != null)
                {
                    this._cmdCancel.Click += handler;
                }
            }
        }
    }
}

